package com.lipaluma.field.mapper;

import java.lang.reflect.Field;
import java.util.List;

import com.lipaluma.context.Context;
import com.lipaluma.exceptions.CsvParserValidationException;
import com.lipaluma.field.validator.Validator;
import com.lipaluma.xml.mapping.XmlFieldMapping;

/**
 * A MapColumn must implements {@link FieldValidatedOnEachValue} if you want that your column can add dynamically a new validator
 * @author mario.soares
 */
public interface FieldValidatedOnEachValue {

	/**
	 * Set each value extracted for the field as required
	 * @param required
	 */
	void eachValueIsRequired(boolean required);

	/**
	 * Add a new validator on each value
	 * @param validator
	 */
	void addNewValidatorOnEachValue(Validator validator);

	/**
	 * init the Validator on each value by annotations
	 * @param context TODO
	 * @param field Field of the target entity
	 */
	void initValidatorOnEachValue(Context context, Field field);

	/**
	 * init the Validator on each value by xml mapping
	 * @param context TODO
	 * @param field Field of the target entity
	 * @param element the xml element
	 */
	void initValidatorOnEachValue(Context context, Field field, XmlFieldMapping mapping);


	/**
	 * validate each values parsed. When a validation error occurs, a {@link CsvParserValidationException} will be thrown.
	 * @param value value to validate
	 * @throws CsvParserValidationException thrown when there is at least one error of validation
	 */
	void validateEachValues(List<Object> value) throws CsvParserValidationException;

	/**
	 * return the field associated
	 * @return field the field
	 */
	Field getField();
}
